/**
 *
 */
package com.nest.WorkNest.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nest.WorkNest.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 类名称：DeliveryAdapter 类描述： 创建人：何琳 创建时间：2015年7月28日 下午4:28:44
 */
public class DeliveryAdapter extends BaseAdapter {

    private ArrayList<HashMap<String, String>> dataList;
    private Context context;

    public DeliveryAdapter(Context context,
                           ArrayList<HashMap<String, String>> dataList) {
        this.dataList = dataList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.layout_delivery_record_item, null);
            holder.delivery_executor = (TextView) convertView
                    .findViewById(R.id.delivery_executor);
            holder.delivery_number = (TextView) convertView
                    .findViewById(R.id.delivery_number);
            holder.delivery_time = (TextView) convertView
                    .findViewById(R.id.delivery_time);
            holder.delivery_content = (TextView) convertView.findViewById(R.id.delivery_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HashMap<String, String> map = dataList.get(position);
        holder.delivery_executor.setText(map.get("executor"));
        holder.delivery_number.setText(map.get("number"));
        holder.delivery_time.setText(map.get("time"));
        holder.delivery_content.setText(map.get("content"));
        return convertView;
    }

    private class ViewHolder {
        TextView delivery_executor, delivery_number, delivery_time, delivery_content;
    }

    public void update(ArrayList<HashMap<String, String>> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }
}
